import {getCommonFvsList} from "@/api/api.js"
export const initFvsList = {
    data() {
        return {
            fvsList:[],
            fvsDeviceList:[],
        }
    },
    methods: {
        //摄像头列表
        getFvsList(){
            this.fvsList = [];
            let params ={
                deptId:this.$store.state.porjectObject.deptId
            }
            getCommonFvsList(params).then(res=>{
                if(res.code == 200) {
                 this.fvsDeviceList = res.data.list;
                    for(let i =0; i<this.fvsDeviceList.length;i++ ) {
                        let obj ={
                            value:this.fvsDeviceList[i].groupId,
                            label:this.fvsDeviceList[i].groupName,
                            children:[],
                        }
                        this.fvsList.push(obj)
                    }
                    let hash = {};
                    this.fvsList = this.fvsList.reduceRight((item, next) => {
                        hash[next.value] ? '' : hash[next.value] = true && item.push(next);
                        return item
                    }, []);
                    for(let i = 0; i < this.fvsDeviceList.length; i++) {
                        for(let j = 0; j <this.fvsList.length; j++) {
                            if(this.fvsDeviceList[i].groupId == this.fvsList[j].value){
                                let obj ={
                                    value:this.fvsDeviceList[i].id,
                                    label:this.fvsDeviceList[i].name,
                                }
                                this.fvsList[j].children.push(obj)
                            }
                        }
                    }
                } else {
                    this.$Message.warning(res.msg);
                }
            }).catch(error=>{
                console.log(error)
            })
        }

    },
    mounted() {
    },
}
